package com.study.hot.jetpack.room.db

import androidx.room.*

/**
 * <pre>
 *     author : slx
 *     time   : 2021/02/25
 *     desc   :
 * </pre>
 */
@Dao
interface UserDao {

    @Query("select * from t_user where userId=:id")
    fun queryUserById(id: Long): User

    @Query("select * from t_user")
    fun queryAllUser(): List<User>

    // onConflict当数据库存在要插入的对象时策略，此处为替换
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun addUser(user: User)

    @Delete
    fun deleteUser(user: User)

    @Query("delete from t_user")
    fun deleteAll()

    @Query("delete from t_user where userId in (:ids)")
    //fun deleteByUserIDs(vararg ids: Long)
    fun deleteByUserIDs(ids: List<Long>)

    @Update
    fun updateUser(user: User)

    // 插入、删除、更新也可以通过@Query制定SQL语句
    @Query("update t_user set user_name= :userName where userId=:userId")
    fun updateUserName(userName: String, userId: Long)
}